<?php
if (!defined("_INDEX")) { header("Location: /"); die; }

if ($this_city != 0)
	goToPage("http://".DOMAIN.$_SERVER['REQUEST_URI']);

if (!$user->isAdmin() && $route->getAdminPlace() != 'enter')
{
	require_once ADMIN.DS."authorization.php";
	die;
}

if (!isset($_COOKIE['city_admin']))
{
	setcookie("city_admin",1,time()+63072000,"/");
	if (!isset($_SESSION['city_admin']))
		$_SESSION['city_admin'] = 1;
}
else
	$_SESSION['city_admin'] = $_COOKIE['city_admin'];

$current_admin_city = $db->getRow("select * from `city` where `city_id` = '$_SESSION[city_admin]' limit 1");
if (!$current_admin_city)
{
	$current_admin_city = $db->getRow("select * from `city` order by `city_id` limit 1");
	setcookie("city_admin",$current_admin_city['city_id'],time()+63072000,"/");
	$_SESSION['city_admin'] = $current_admin_city['city_id'];
}

switch ($route->getAdminPlace()) {

	case "enter":	require_once ADMIN.DS."enter.php"; break;
	case "logout":	$user->logout(); header("Location: ".$_SERVER['HTTP_REFERER']); break;
	
	// companies
	case "companies":	require_once ADMIN.DS."companies".DS."main.php"; break;
	case "amount":		require_once ADMIN.DS."amount".DS."main.php"; break;
	case "offices":		require_once ADMIN.DS."offices".DS."main.php"; break;
	case "c_votes":		require_once ADMIN.DS."c_votes".DS."main.php"; break;
	case "services":	require_once ADMIN.DS."services".DS."main.php"; break;
	case "reliability":	require_once ADMIN.DS."reliability".DS."main.php"; break;
	
	// brokers
	case "brokers":		require_once ADMIN.DS."brokers".DS."main.php"; break;
	case "b_votes":		require_once ADMIN.DS."b_votes".DS."main.php"; break;

	// brokers
	case "tips":		require_once ADMIN.DS."tips".DS."main.php"; break;
	case "sections":	require_once ADMIN.DS."tip_sections".DS."main.php"; break;
	case "questions":	require_once ADMIN.DS."questions".DS."main.php"; break;

	// common
	case "city":		require_once ADMIN.DS."city".DS."main.php"; break;
	case "news":		require_once ADMIN.DS."news".DS."main.php"; break;
	case "smiles":		require_once ADMIN.DS."smiles".DS."main.php"; break;

	// site
	case "users":		require_once ADMIN.DS."users".DS."main.php"; break;
	case "banners":		require_once ADMIN.DS."banners".DS."main.php"; break;
	case "partners":	require_once ADMIN.DS."partners".DS."main.php"; break;
	case "monitor":		require_once ADMIN.DS."monitor".DS."main.php"; break;
	case "errors":		require_once ADMIN.DS."errors".DS."main.php"; break;
	case "settings":	require_once ADMIN.DS."settings".DS."main.php"; break;
	
	default: 		goToPage("/admin/companies");
}

?>